/*
 * @lc app=leetcode.cn id=189 lang=cpp
 *
 * [189] 旋转数组
 */

// @lc code=start
class Solution {
public:
    void rotate(vector<int>& nums, int k) {
        //原地操作
        //1 2 3 4 5 6 7
        //7 6 5 4 3 2 1
        //5 6 7 1 2 3 4
        k = k % nums.size();
        rot(nums, 0, nums.size() - 1);
        rot(nums, 0, k - 1);
        rot(nums, k, nums.size() - 1);
    }

    void rot(vector<int> &nums, int x, int y){
        while(x < y){
            swap(nums[x], nums[y]);
            x++;
            y--;
        }
    }
};
// @lc code=end

